<?php

/**
 * This is the model class for table "word".
 *
 * The followings are the available columns in table 'word':
 * @property integer $wid
 * @property string $spell
 * @property string $phonetic
 * @property string $chinese
 * @property integer $sid
 * @property string $sentence
 * @property string $sound
 * @property string $slow_sound
 * @property integer $cid
 * @property string $sentence_sound
 *
 * The followings are the available model relations:
 * @property Catalog $c
 * @property Speech $s
 */
class Word extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Word the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'word';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('sid, cid', 'numerical', 'integerOnly'=>true),
			array('spell', 'length', 'max'=>20),
			array('sound, slow_sound, sentence_sound', 'length', 'max'=>200),
			array('sentence,chinese,phonetic', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('wid, spell, phonetic, chinese, sid, sentence, sound, slow_sound, cid, sentence_sound', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'c' => array(self::BELONGS_TO, 'Catalog', 'cid'),
			's' => array(self::BELONGS_TO, 'Speech', 'sid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'wid' => 'Word_ID',
			'spell' => 'Spell',
			'phonetic' => 'Phonetic',
			'chinese' => 'Chinese',
			'sid' => 'Speech',
			'sentence' => 'Sentence',
			'sound' => 'Sound file',
			'slow_sound' => 'Slow sound file',
			'cid' => 'Catalog',
			'sentence_sound' => 'Sentence sound file',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('wid',$this->wid);
		$criteria->compare('spell',$this->spell,true);
		$criteria->compare('phonetic',$this->phonetic,true);
		$criteria->compare('chinese',$this->chinese,true);
		$criteria->compare('sid',$this->sid);
		$criteria->compare('sentence',$this->sentence,true);
		$criteria->compare('sound',$this->sound,true);
		$criteria->compare('slow_sound',$this->slow_sound,true);
		$criteria->compare('cid',$this->cid);
		$criteria->compare('sentence_sound',$this->sentence_sound,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}